#include <graphics/TextureManager.h>

namespace ne
{
    template<> TextureManager* Singleton<TextureManager>::mpInstance = 0;

    TextureManager::TextureManager()
    {
        mResourceType = "Texture";
        std::cout << "Construct Texture Manager\n";
    }

    TexturePtr TextureManager::createTexture(const std::string &name,
                                             const std::string &fileName,
                                             const TextureType type,
                                             const TextureFormat format,
                                             const PixelType pt,
                                             const uint32_t width,
                                             const uint32_t height,
                                             const uint32_t depth)
    {
        TexturePtr pTexture(create(name, fileName, true));
        pTexture->createInternalTexture(type, format, PixelFormat(format), pt,
                                        width, height, depth);
        pTexture->load();
        return pTexture;
    }

    TexturePtr TextureManager::createTextureFromFile(const std::string &name,
                                                     const std::string &fileName,
                                                     const TextureFormat format)
    {
        TexturePtr pTexture(create(name, fileName));
        pTexture->setFormat(format);
        return pTexture;
    }

    TextureManager::~TextureManager()
    {
        std::cout << "Disconstruct Texture Manager\n";
    }

    TextureManager& TextureManager::GetSingleton()
    {
        assert(mpInstance);
        return *mpInstance;
    }

    TextureManager* TextureManager::GetSingletonPtr()
    {
        return mpInstance;
    }

    Resource* TextureManager::createImplement(const uint64_t id,
                                              const std::string &name,
                                              const std::string &fileName,
                                              const bool isManual,
                                              ManualResourceLoader *pLoader)
    {
        return new Texture(this, id, name, fileName, isManual, pLoader);
    }
}
